package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysRoadInfo;
import com.ruoyi.system.service.ISysRoadInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 道路信息Controller
 * 
 * @author ruoyi
 * @date 2022-01-14
 */
@Controller
@RequestMapping("/system/road")
public class SysRoadInfoController extends BaseController
{
    private String prefix = "system/road";

    @Autowired
    private ISysRoadInfoService sysRoadInfoService;

    @RequiresPermissions("system:road:view")
    @GetMapping()
    public String road()
    {
        return prefix + "/road";
    }

    /**
     * 查询道路信息列表
     */
    @RequiresPermissions("system:road:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysRoadInfo sysRoadInfo)
    {
        startPage();
        List<SysRoadInfo> list = sysRoadInfoService.selectSysRoadInfoList(sysRoadInfo);
        return getDataTable(list);
    }

    /**
     * 导出道路信息列表
     */
    @RequiresPermissions("system:road:export")
    @Log(title = "道路信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysRoadInfo sysRoadInfo)
    {
        List<SysRoadInfo> list = sysRoadInfoService.selectSysRoadInfoList(sysRoadInfo);
        ExcelUtil<SysRoadInfo> util = new ExcelUtil<SysRoadInfo>(SysRoadInfo.class);
        return util.exportExcel(list, "道路信息数据");
    }

    /**
     * 新增道路信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存道路信息
     */
    @RequiresPermissions("system:road:add")
    @Log(title = "道路信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysRoadInfo sysRoadInfo)
    {
        return toAjax(sysRoadInfoService.insertSysRoadInfo(sysRoadInfo));
    }

    /**
     * 修改道路信息
     */
    @RequiresPermissions("system:road:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        SysRoadInfo sysRoadInfo = sysRoadInfoService.selectSysRoadInfoById(id);
        mmap.put("sysRoadInfo", sysRoadInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存道路信息
     */
    @RequiresPermissions("system:road:edit")
    @Log(title = "道路信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysRoadInfo sysRoadInfo)
    {
        return toAjax(sysRoadInfoService.updateSysRoadInfo(sysRoadInfo));
    }

    /**
     * 删除道路信息
     */
    @RequiresPermissions("system:road:remove")
    @Log(title = "道路信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysRoadInfoService.deleteSysRoadInfoByIds(ids));
    }
}
